<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no, viewport-fit=cover" />
    <title>诚赉健康</title>
    <link rel="stylesheet" href="../css/vant.css">
    <link rel="stylesheet" href="./css/index1.css">
</head>

<body>
    <div id="app" v-cloak>
        <div class="loading" v-if="mask">
            <img src="../img/load.gif">
        </div>

        <div class="conBox">
            <div class="titleBox">
                当前会场签到人数：{{(userList.length==0?0:xuniNum)+userList.length}} 人
            </div>

            <div class="userCon">
                <div class="userBox" v-for="(item,index) in userList" :key="index">
                    <div>{{item.firstName}}</div>
                    <div>
                        <div>电话：{{item.tel}}</div>
                    </div>
                </div>
            </div>
            <div class="showTip">活动仅展示6人</div>

            <div class="btnBox">
                <div class="saveInfoBtn" @click="toPage(1)">
                    去抽奖
                </div>
                <div class="saveInfoBtn saveInfoBtn1" @click="toPage(2)" v-if="userInfo.userStatus==1">
                    客户列表
                </div>

            </div>


        </div>
    </div>


    <script src="../js/vue.min.js"></script>
    <script src="../js/flex_ible/lib-flexible.js"></script>
    <script src="../js/vue-lazyload.js"></script>
    <script src="../js/vant.min.js"></script>
    <script src="../js/vue-lazyload.js"></script>
    <script src="../js/mui.min.js"></script>
    <script src="../js/url.js" type="text/javascript" charset="utf-8"></script>
    <script src="./js/url.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/ajax.js"></script>
    <script src="../js/city.data-3.js"></script>
    <script type="text/javascript" src="https://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
    <script>
        function GetQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        }

        var code = GetQueryString("code");
        var state = GetQueryString("state");

        // alert(code)
        // alert(state)


        var vm = new Vue({
            el: "#app",
            data: {
                mask: false,
                userInfo: {},
                userList: [],
                xuniNum: 0,
                isEnd: false,// 活动是否进行中
            },
            created() {
                this.getActiveInfo()
                // this.getSalesmanList()
            },
            methods: {
                getInfo() {
                    var _this = this;
                    _this.mask = true;
                    ajax({
                        url: newUrl4 + "/meeting/getSignin",
                        type: 'post',
                        data: {
                            code: code,
                        },
                        dataType: 'json',
                        timeout: 10000,
                        contentType: "application/json",
                        success: function (res) {
                            // alert(res)
                            var res = JSON.parse(res)
                            if (res.flag) {
                                console.log(res);
                                _this.userInfo = res.data
                                if (_this.userInfo.userName != null) {
                                    localStorage.signinUserId = _this.userInfo.signinId
                                    _this.getSalesmanList()
                                } else {
                                    _this.userInfo.userStatus = state
                                    localStorage.signinUser = JSON.stringify(_this.userInfo)
                                    window.location.replace('./userInfo.html')
                                }
                            } else {
                                _this.$toast('登录失败，请退出重新登录')
                            }
                            _this.mask = false

                        },
                    })
                },

                toPage(flag) {

                    if (flag == 1) {
                        window.location.replace("./lottery.html")
                    } else {
                        window.location.replace("./userList.html")
                    }

                },

                // 获取用户列表
                getSalesmanList() {
                    var _this = this;
                    _this.mask = true;
                    ajax({
                        url: newUrl4 + "meeting/getSigninList",
                        type: 'post',
                        data: {
                            salesman: 0,
                            flag: 1 // 0 业务员获取信息   1 随机获取首页用户
                        },
                        dataType: 'json',
                        timeout: 10000,
                        contentType: "application/json",
                        success: function (res) {
                            console.log(res);
                            // alert(res)
                            var res = JSON.parse(res)
                            if (res.flag) {

                                res.data = res.data.filter(item => item.userName != null)
                                console.log(res.data);

                                res.data.forEach(item => {

                                    item.firstName = item.userName.substr(0, 1)
                                    item.tel = item.userPhone.substr(0, 3) + '****' + item.userPhone.substr(7, 4)
                                })

                                _this.userList = res.data

                                // _this.userList.sort(() => Math.random() - 0.5);
                                // console.log(_this.userList);

                                // // alert(JSON.stringify(_this.userList))

                                // if (_this.userList.length > 6) {
                                //     _this.userList = _this.userList.slice(0, 6)
                                // }

                                // // alert(JSON.stringify(_this.userList))


                            }
                            _this.mask = false
                        },
                    })
                },
                // 获取活动信息
                getActiveInfo() {
                    var _this = this;
                    _this.mask = true;
                    ajax({
                        url: newUrl4 + "meeting/listMeeting",
                        type: 'post',
                        data: {
                            id: - 1
                        },
                        dataType: 'json',
                        timeout: 10000,
                        contentType: "application/json",
                        success: function (res) {
                            // console.log(res);
                            var res = JSON.parse(res)
                            if (res.flag) {
                                console.log(res.data[0]);
                                var info = res.data[0]
                                _this.xuniNum = Number(info.name)

                                // alert(new Date(info.endTime).getTime())
                                // alert(new Date().getTime())
                                console.log(new Date().getTime());
                                console.log(new Date(info.endTime).getTime());
                                _this.isEnd = new Date().getTime() > new Date(info.endTime).getTime()


                                // alert(_this.isEnd)


                                if (_this.isEnd) {
                                    _this.$dialog.alert({
                                        title: '提示',
                                        message: '本次活动已结束',
                                        confirmButtonText: '立即退出',
                                    })
                                        .then(function () {
                                            //安卓
                                            document.addEventListener('WeixinJSBridgeReady', function () { WeixinJSBridge.call('closeWindow'); }, false);
                                            // IOS
                                            WeixinJSBridge.call('closeWindow');
                                        })
                                        .catch(function () {
                                            // on cancel
                                        });
                                } else {
                                    _this.getInfo()
                                }
                            }
                            _this.mask = false
                        },
                    })
                },
            }
        })

    </script>

</body>

</html>